//
//  SearchViewController.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 16/3/30.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "SearchViewController.h"

@interface SearchViewController (){

    UIView *superView;
    UIImageView *view;
    UITapGestureRecognizer *tap;
    
}

@end

@implementation SearchViewController


-(instancetype)initWithBlock:( void(^)(NSDictionary *dic) )cb{

    self = [super init];
    if (self) {
        
    }
    
    _cb = cb;
    
    return self;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    superView = [[UIView alloc]init];
    [self.view addSubview:superView];
    [superView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.view.mas_top);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
    
    [self createUI];
}

#pragma mark - use UI
-(void)createUI{

    //*** create navgitation
    [self navCreate];
    
    //*** use the searchView
    _searchView = [[SearchView alloc]initWithBlock:^(NSDictionary *dic) {
        _cb(dic);
        
    }];
    _searchView.pageID = self.pageID;
    _searchView.tableID = self.tableID;
    _searchView.fieldArr = self.dataArr;
//    _searchView.searchUrl = self.searchUrl;

    _searchView.delegeteView = self.delegate;
    
    _searchView.currentShowView = self;
    [_searchView settimerView:self.view];
    [superView addSubview:_searchView];
//    _searchView.frame = CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 0);
    [_searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.top.equalTo(view.mas_bottom);
        make.width.equalTo(self.view.mas_width);
        make.bottom.equalTo(superView.mas_bottom);
    }];

    [_searchView startAnima];
    
    
}

#pragma mark - create Nav customer
-(void)navCreate{

    view  = [[UIImageView alloc]init];
    
    view.userInteractionEnabled = YES;
    
    [superView addSubview:view];
    
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(superView.mas_left);
        make.right.equalTo(superView.mas_right);
        make.top.equalTo(superView.mas_top);
        make.height.equalTo(@(64));
    }];
    if ([getUIStyle() isEqualToString:STYLE0]) {
        view.image = [UIImage imageNamed:@"nav3"];
    }else{
        view.image = [UIImage imageNamed:@"redbar"];
    }
    
    
    
    UIButton *backBtn = [[UIButton alloc]init];
    
    [view addSubview:backBtn];
    backBtn.frame = CGRectMake(13, 13+20, 11, 37/2);
    [backBtn setBackgroundImage:[UIImage imageNamed:@"形状1-19-拷贝-4"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(navBack) forControlEvents:UIControlEventTouchUpInside];
    
    tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(navBack)];
    
    [view addGestureRecognizer:tap];
}

-(void)navBack{
[self dismissViewControllerAnimated:YES completion:^{
    
}];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)dealloc{
    [tap removeTarget:self action:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
